package swust.com.mytestdemo;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;//未被使用则可删除


import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)




public class TextOne {
  //FirefoxDriver wd;
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();
  String myH;
  String myW;
  String expBmi;

  
  @Before  //在测试之前执行的程序,每次Test被执行时，都要被执行（Test可以有多个）
  public void setUp() throws Exception {
	System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
	System.setProperty("webdriver.firefox.marionette", "D:\\Program Files\\Mozilla Firefox\\geckodriver-v0.18.0-win64.zip");
    driver = new FirefoxDriver();
    //baseUrl = "http://cn.onlinebmicalculator.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }
 
  @Parameters    
	public static Collection data() {
	 // Object[][]a = new Object [3][3];
	  //a[0][0] = "";
		return Arrays.asList(new Object[][]{
			{"159","60","24"},{"180","60","19"},{"159","60","17"}
			});
	}
  //构造函数,对变量进行初始化
  public TextOne(String h,  
		String w,
		String bmi){
      this.myH = h;
      this.myW = w;
      this.expBmi = bmi;
  }
  @Test
  public void  PrintParameters() {
	  System.out.println("myH：" + myH);
	  System.out.println("myW：" + myW);
	  System.out.println("expBmi：" + expBmi + "\n");
  }

/*
  @Test
  public void test00() {
	  fail("No yet implemented");
  }
  
  @Test
  public void test01() {
	  Assert.assertEquals(true, false);
  }
  
  @Test
  public void test02() {
	  Assert.assertEquals(true, true);
  }
  
  @Test
  public void test03() {
	  System.out.println("test03");
	  int a = 5;
	  Assert.assertEquals(a, 5);
	  Assert.assertEquals(true, false);
  }
  */
  /*
  @Test
  public void testTextOne() throws Exception {
    driver.get("http://cn.onlinebmicalculator.com/");
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys("190");
    driver.findElement(By.name("f_submit")).click();
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys("180");
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys("70");
    driver.findElement(By.name("f_submit")).click();
    driver.findElement(By.name("f_height")).clear();
    driver.findElement(By.name("f_height")).sendKeys("175");
    driver.findElement(By.name("f_weight")).clear();
    driver.findElement(By.name("f_weight")).sendKeys("60");
    driver.findElement(By.name("f_submit")).click();
    
    WebElement element = driver.findElement(By.className("bmi_info")).findElement(By.tagName("span"));
    String bmi = element.getText();
    System.out.println("BMI：" + bmi);
    Assert.assertEquals("19.6", bmi);
    }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
  */
}
